$(function() {
    //执行滑动验证码方法
    verifyFn('320','160','320',function (gapLeft,moveLeft) {//回调
        $("[name='gapLeft']").val(gapLeft);
        $("[name='moveLeft']").val(moveLeft);
    });

    $("input").focus(function(){
        $(".errorMessage").hide();
        $(".errorTips").html("");
    });
    var largeHeader = document.getElementById('wrap'),
        height = window.innerHeight;
    largeHeader.style.height = height+'px';
    //回车事件
    $('body').on('keyup', 'input[name="mobile"], ' +
        'input[name="mobileCode"],input[name="passWord"], ' +
        'input[name="confirmPwd"]', function (event) {
        event = event || window.event;
        if (event && event.keyCode == 13) { //回车事件
            $('#submitRetrievePassword').click();
        }
    }).on('keyup','input[name="loginAccount"],input[name="password"],input[name="captcha"]', function (event) { //回车事件
        event = event || window.event;
        if (event && event.keyCode == 13) { //回车事件
            $('#loginBtn').click();
        }
    }).on('click','#retrievePassword',function () {
        $("#loginDiv").hide();
        $("#passWordDiv").show();
    }).on('click', 'img.picode-pic', function () { //点击更换验证码
        var _src = $(this).attr('src');
        var _arr = _src.split("?");
        $(this).attr('src', _arr[0] + '?rnd=' + Math.random());
    }).on('click','#weiXinLogin',function () {//微信图片点击方法
        window.location.href= baseloaction+"/web/thirdLogin/authLogin?appType=WEIXIN";
    }).on('click','#qqLogin',function () {//QQ登录
        window.location.href = baseloaction + '/web/thirdLogin/authLogin?appType=QQ';
    }).on('click','#loginBtn',function () {//登录
        var _loginAccount = $('input[name="loginAccount"]').val();
        var passWord = $('input[name="password"]').val();
        var autoThirty = "false";
        var gapLeft = $('input[name="gapLeft"]').val();
        var moveLeft = $('input[name="moveLeft"]').val();
        if($('input[name="autoThirty"]:checked').val()){
            autoThirty="true";
        }
        if(passWord !=null && $.trim(passWord)!=''){
            var encrypt = new JSEncrypt();
            encrypt.setPublicKey(publicKey);
            passWord= encrypt.encrypt(passWord);
        }
        if(gapLeft !=null && $.trim(gapLeft) !=''){
            var encrypt = new JSEncrypt();
            encrypt.setPublicKey(publicKey);
            gapLeft = encrypt.encrypt(gapLeft);
        }
        if(moveLeft !=null && $.trim(moveLeft) !=''){
            var encrypt = new JSEncrypt();
            encrypt.setPublicKey(publicKey);
            moveLeft = encrypt.encrypt(moveLeft);
        }
        $.ajax({
            url:baseloaction + "/web/user/doLogin",
            data:{
                "loginAccount":_loginAccount,
                "password":passWord,
                "autoThirty":autoThirty,
                "gapLeft":gapLeft,
                "moveLeft":moveLeft,
                'sign':sign
            },
            dataType:"json",
            type:"post",
            success:function (result) {
                if(result.success==true){
                    var toUrl =result.url;
                    if(toUrl==null){
                        redirectURL(baseloaction +'/web/uc/course/user/index');
                    }else{
                        window.location.href = baseloaction +toUrl;
                    }
                }else{
                    $(".errorMessage").show();
                    $(".errorTips").html(result.message);
                    sign = result.keyMap.sign;
                    publicKey = result.keyMap.publicKey;
                }
            },
            error:function (error) {
                icModale(0,'','系统错误，登录失败');
            }
        });
    });
});